#this is a little stand alone animation viewer that lets me preview animations without plugging them into the game
#the left and right arrow increase and decrease the frame repeat amount
import pygame, sys, os

from pygame.locals import *
from mouse import *

class game_c:
    def __init__(self, programTitle):
        """ DISPLAY INITIALISATION """
        self.windowSize=(800,1000)
        self.window = pygame.display.set_mode(self.windowSize, HWSURFACE|DOUBLEBUF)
        pygame.display.set_caption(programTitle)
        self.screen = pygame.display.get_surface()

        """ GAME VARIABLES """
        self.endGame = False
        self.mouse = mouse_c
        self.width=32
        self.height=1000
        self.frame = 0
        self.gameClock = pygame.time.Clock()
        self.msecsSinceLastDraw = 0
        self.dir = 1
        self.animLength = 23
        
        """ LOAD MEDIA """
        #self.anim = pygame.image.load("dev/dude-Scratch.gif")
        self.anim = pygame.image.load("data/dude-Final_mask.png")
                
        """ START YOUR ENGINE """
        self.main()

    def checkEvents(self, events):
        for event in events:
            if event.type == QUIT:
                self.endGame=True
            elif event.type == KEYDOWN:
                if event.key == K_ESCAPE:
                    self.endGame=True
                if event.key == 275:
                    self.animLength+=1
                if event.key == 276:
                    self.animLength-=1
                #print event.key
    
    def draw(self):
        self.screen.fill((0,0,0,0), [0,0,self.width, self.height])
        self.screen.blit(self.anim, (0, 0), [self.frame * self.width, 0, self.width, self.height])
        self.frame += self.dir
        
        #loop at end or play in reverse at end
        if self.frame == self.animLength or self.frame == 0:
            self.frame=0
            #self.dir*=-1
            
        pygame.display.flip()

    def main(self):
        while self.endGame != True:
            self.checkEvents(pygame.event.get())
            self.msecsSinceLastDraw += self.gameClock.tick()
            if self.msecsSinceLastDraw>60:
                self.msecsSinceLastDraw=0
                self.draw()

if __name__=="__main__":
    pygame.init()
    game = game_c('Default Program')
